package cn.tedu.collection;

import java.util.Objects;

/*本类用于测试Set集合存放自定义的引用类型对象*/
//1,创建自定义引用类型学生类
public class Student {
    //2,创建属性
    String name;
    int id;
    //3,全参构造
    public Student(String name, int id) {
        this.name = name;
        this.id = id;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", id=" + id +
                '}';
    }
    //添加equals()与hashCode()方法
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return id == student.id && Objects.equals(name, student.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, id);
    }
}
